var ctx=window.daijia.ctx;
var result=window.daijia.result;
var year=window.daijia.year;
$(document).ready(function(){
	
	loadData();
	$("#search_button").click(function(){
		
		loadData();
	});
	//导出。。。。。。。。
	//导出数量
	$("#allAmount").click(function(){
		if($(this).is(':checked')){
			$("#amounts").attr("disabled",true);
		}
		else{
			$("#amounts").attr("disabled",false);
		}
	});
	
	//开始导出
	$("#export_button").click(function(){
		
		if(!$("#allAmount").is(':checked')){
			var amounts=$("#amounts").val();
			if(amounts==""){
				$.scojs_message("请输入导出数量", $.scojs_message.TYPE_ERROR);
				return false;
			}
			else if(amounts<=0){
				$.scojs_message("导出数量最少为1条", $.scojs_message.TYPE_ERROR);
				return false;
			}
		}
		
		window.location=ctx+"/chart/exportDay?"+$("#ExportForm").serialize();
	});
	
	function loadData(){
		
		if($('#loadblacklayer').length==0){
			var dw = $(".table").width();
			var dh = $(".table").height();
			var backlayer ="<div id='loadblacklayer'><div style='margin-top:"+(dh/2)+"px;margin-left:"+(dw/2)+"px;'><img src='"+ctx+"/assets/css/images/loading.gif' /></div></div>"
			$(".table tbody").append(backlayer);
			$('#loadblacklayer').css({"z-index":"9","background":"#000","opacity":"0.5","position":'absolute',"top":0,"width":dw,"height":dh});
		}
		
		var newcontent = '';
		$.ajax({
			
	        url : ctx+'/chart/tableOrderDayDate',
	        type:'GET',
	        async:false,
	        dataType : 'json',
	        data : {
	        
	        	"year":$("#year").val(),
	        	"month":$("#month").val(),
	        	"companyId":$("#companyId").val()
	        },
	        success : function(result){
	        	
	        	if(result.length>0){
	        		
	        		$(result).each(function(index,data){
	        			
		    newcontent+="<tr>"+
							"<td>"+data.time+"</td>"+
							"<td>"+data.cancelAmount+"</td>"+
							"<td>"+data.finishedAmount+"</td>"+
							"<td>"+data.money+"</td>"+
							
						"</tr>";
	        		});
	        	}
	        	$(".table tbody").html(newcontent);
	    		$('#loadblacklayer').remove();
	    		newTotalElements=result.totalElements;
	        }
		});
		
		return newTotalElements;
	}

});
	

